//
//  StoreOrderTableViewCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/6.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "StoreOrderTableViewCell.h"

@interface StoreOrderTableViewCell ()

@property (nonatomic, strong) UIImageView   * headImage;
@property (nonatomic, strong) UILabel       * nameLabel;
@property (nonatomic, strong) UILabel       * detailLabel;
@property (nonatomic, strong) UILabel       * moneyLabel;
@property (nonatomic, strong) UILabel       * statuLabel;
@property (nonatomic, strong) UILabel       * numLabel;
@property (nonatomic, strong) UIButton      * leftBtn;
@property (nonatomic, strong) UIButton      * rightBtn;

@end

@implementation StoreOrderTableViewCell

+ (StoreOrderTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"StoreOrderTableViewCell";
    StoreOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[StoreOrderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

-(void)setShopOrderListDataModel:(ShopOrderListDataModel *)shopOrderListDataModel
{
    _shopOrderListDataModel = shopOrderListDataModel;
    
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:shopOrderListDataModel.pic]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@",shopOrderListDataModel.goods_name];
    self.moneyLabel.text = [NSString stringWithFormat:@"%@元",shopOrderListDataModel.goods_allprice];
    self.numLabel.text = [[NSString stringWithFormat:@"共%@件商品，",shopOrderListDataModel.goods_nums] stringByAppendingString:[NSString stringWithFormat:@"合计￥%@",shopOrderListDataModel.total_fee]];
    
    if ([shopOrderListDataModel.order_status isEqualToString:@"0"]) {
        self.statuLabel.text = @"已取消";
        self.leftBtn.hidden = YES;
        [self.rightBtn setTitle:@"查看详情" forState:UIControlStateNormal];
    }else if ([shopOrderListDataModel.order_status isEqualToString:@"1"]){
        self.statuLabel.text = @"待付款";
        self.leftBtn.hidden = NO;
        [self.leftBtn setTitle:@"取消订单" forState:UIControlStateNormal];
        [self.rightBtn setTitle:@"立即付款" forState:UIControlStateNormal];
    }else if ([shopOrderListDataModel.order_status isEqualToString:@"2"]){
        self.statuLabel.text = @"待发货";
        self.leftBtn.hidden = NO;
        [self.leftBtn setTitle:@"取消订单" forState:UIControlStateNormal];
        [self.rightBtn setTitle:@"提示发货" forState:UIControlStateNormal];
    }else if ([shopOrderListDataModel.order_status isEqualToString:@"3"]){
        self.statuLabel.text = @"待收货";
        self.leftBtn.hidden = NO;
        [self.leftBtn setTitle:@"确认收货" forState:UIControlStateNormal];
        [self.rightBtn setTitle:@"查看物流" forState:UIControlStateNormal];
    }else if ([shopOrderListDataModel.order_status isEqualToString:@"4"]){
        self.statuLabel.text = @"待评价";
        self.leftBtn.hidden = YES;
        [self.leftBtn setTitle:@"申请售后" forState:UIControlStateNormal];
        [self.rightBtn setTitle:@"立即评价" forState:UIControlStateNormal];
    }else if ([shopOrderListDataModel.order_status isEqualToString:@"5"]){
        self.statuLabel.text = @"已完成";
        self.leftBtn.hidden = YES;
        [self.rightBtn setTitle:@"查看详情" forState:UIControlStateNormal];
//        [self.rightBtn setTitle:@"申请售后" forState:UIControlStateNormal];
    }else if ([shopOrderListDataModel.order_status isEqualToString:@"6"]){
        self.statuLabel.text = @"售后中";
        self.leftBtn.hidden = YES;
        [self.rightBtn setTitle:@"查看详情" forState:UIControlStateNormal];
    }else {
        self.statuLabel.text = @"售后完成";
        self.leftBtn.hidden = YES;
        [self.rightBtn setTitle:@"查看订单" forState:UIControlStateNormal];
    }
}

-(void)leftClicked
{
    if (_leftClick) {
        _leftClick();
    }
}

-(void)rightClicked
{
    if (_rightClick) {
        _rightClick();
    }
}

- (void)createSubView {
    self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(15), ScreenX375(140), ScreenX375(78))];
    self.headImage.layer.cornerRadius = ScreenX375(5);
    self.headImage.clipsToBounds = YES;
    self.headImage.image = [UIImage imageNamed:@"头部背景"];
    [self addSubview:self.headImage];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(163), ScreenX375(14), ScreenX375(150), ScreenX375(16))];
    self.nameLabel.text = @"纸箱纸板";
    self.nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.nameLabel.font = Kfont(14);
    [self addSubview:self.nameLabel];
    
    self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(113), ScreenX375(14), ScreenX375(100), ScreenX375(17))];
    self.moneyLabel.textColor = ThemeColor;
    self.moneyLabel.font = Kfont(12);
    self.moneyLabel.textAlignment = NSTextAlignmentRight;
    self.moneyLabel.text = @"100元";
    [self addSubview:self.moneyLabel];
    
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    self.detailLabel.textColor = REXADECIMALCOLOR(@"#999999");
    self.detailLabel.font = Kfont(12);
    [self addSubview:self.detailLabel];
    
    UIImageView *sLine = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(108), SCREEN_WIDTH - ScreenX375(26), 0.5)];
    sLine.image = [UIImage imageNamed:@"虚线"];
    [self addSubview:sLine];
    
    self.statuLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(117), ScreenX375(80), ScreenX375(15))];
//    self.statuLabel.text = @"代付款";
    self.statuLabel.textColor = ThemeColor;
    self.statuLabel.font = Kfont(12);
    [self addSubview:self.statuLabel];
    
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(193), ScreenX375(117), ScreenX375(180), ScreenX375(15))];
    self.numLabel.text = @"共100件商品，合计￥1200.00";
    self.numLabel.textColor = REXADECIMALCOLOR(@"#333333");
    self.numLabel.font = Kfont(12);
    self.numLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.numLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenX375(141), SCREEN_WIDTH, 0.5)];
    line.backgroundColor = LineColor;
    [self addSubview:line];
    
    self.leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(164), ScreenX375(151), ScreenX375(94), ScreenX375(30))];
    self.leftBtn.backgroundColor = ThemeColor;
    self.leftBtn.layer.cornerRadius = ScreenX375(15);
    self.leftBtn.clipsToBounds = YES;
    [self.leftBtn addTarget:self action:@selector(leftClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.leftBtn.titleLabel.font = Kfont(14);
    [self addSubview:self.leftBtn];
    
    self.rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(268), ScreenX375(151), ScreenX375(94), ScreenX375(30))];
    self.rightBtn.backgroundColor = ThemeColor;
    self.rightBtn.layer.cornerRadius = ScreenX375(15);
    self.rightBtn.clipsToBounds = YES;
    [self.rightBtn setTitle:@"付款" forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.rightBtn addTarget:self action:@selector(rightClicked) forControlEvents:UIControlEventTouchUpInside];
    self.rightBtn.titleLabel.font = Kfont(14);
    [self addSubview:self.rightBtn];
}



@end
